package demo.src.main.com.example.shiro.config;

import org.apache.shiro.authc.*;
import org.apache.shiro.authz.AuthorizationInfo;
import org.apache.shiro.realm.AuthorizingRealm;
import org.apache.shiro.subject.PrincipalCollection;

public class UserRealm extends AuthorizingRealm {

   // 授权
    @Override
    protected AuthorizationInfo doGetAuthorizationInfo(PrincipalCollection principalCollection) {
        System.out.println("执行了授权");

        return null;
    }
    // 认证
    @Override
    protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
        System.out.println("执行了认证");

        // 用户名密码 数据库中取
        String name ="root";
        String pwd="1";
         UsernamePasswordToken usrtoken=(UsernamePasswordToken)authenticationToken;
    if (!usrtoken.getUsername().equals(name)){
        return null; // return null 抛出异常 Unknown
    }
    //密码认证，shiro
        return new SimpleAccount( "",pwd,"");
    }
    // 自定义realm 需要去继承autuorizingrealm
}
